package com.blockmeta.bbs.businesslibrary.websocket;

import com.blockmeta.bbs.baselibrary.base.app.BaseApp;
import com.blockmeta.bbs.businesslibrary.R;
import com.google.gson.annotations.SerializedName;

/**
 * 程式實作面的定義
 * @author websocket
 *
 */
public class AppDefine
{
	public enum UpdateMode
	{
		REFRESH,	// 全部更新
		INSERT,
		DELETE,
		UPDATE,		// 更新
		REPLACE,	// 更新, 且對調順序
		IGNORE,		// 忽略此次更新
		CLEAR		// 全部清除
	};

	public enum MergeMode
	{
		INSERT,
		DELETE,
		UPDATE,
		APPEND,
		IGNORE
	};

	public enum EnableLog
	{
		Off(0),
		On(1);

		int m_value;
		EnableLog(int value) { m_value = value; }
		public int getValue() { return m_value; }
	}



	public enum SymbolStale	// 行情是否收盤
	{
		OPEN(0),
		CLOSE(1);

		protected int m_value;
		SymbolStale(int value) { m_value = value; }
		public static SymbolStale getStale(int stale)
		{
			return (stale == 1) ? CLOSE : OPEN;
		}
		public int getValue()
		{
			return m_value;
		}
	}

	public enum SymbolStatus	// 商品是否停牌
	{
		GENERAL(0),
		HALT_BUT_CANCEL(8),
		HALT(9),
		NOT_READY(99);

		protected int m_value;
		SymbolStatus(int value) { m_value = value; }
		public static SymbolStatus getStatus(int status)
		{
			switch (status)
			{
				case 8:
					return HALT_BUT_CANCEL;
				case 9:
					return HALT;
				case 99:
					return NOT_READY;
				default:
					return GENERAL;
			}
		}
		public int getValue()
		{
			return m_value;
		}
	}









	public enum QueryPeroid
	{
		QRY_1W('0'),
		QRY_1M('1'),
		QRY_3M('2'),
		QRY_6M('3'),
		QRY_1Y('4'),
		QUR_ALL('5');

		protected char m_value;
		QueryPeroid(char value) { m_value = value; }

		public String ToString() { return String.valueOf(m_value); }
		public char getValue() { return m_value; }
		public static QueryPeroid getQueryPeroid(char peroid)
		{
			switch(peroid)
			{
				case '0':
					return QRY_1W;
				case '1':
					return QRY_1M;
				case '2':
					return QRY_3M;
				case '3':
					return QRY_6M;
				case '4':
					return QRY_1Y;
				case '5':
					return QUR_ALL;
				default:
					return QRY_1W;
			}
		}
	};

	public enum APP_Environment
	{
		DEV,
		TEST,
		UAT,
		PROD;
	}



	public enum ConnectEnv
	{
		AUTO('A', "AUTO", "AUTO"),
		DEV('D', APP_Environment.DEV.toString(), "DEV"),
		TEST('T', APP_Environment.TEST.toString(), "TEST"),
		UAT('C', APP_Environment.UAT.toString(), "UAT"),
		PROD('P', APP_Environment.PROD.toString(), "PROD");

		protected char 	 m_value;
		protected String m_strEnv;
		protected String m_strDisplay;

		ConnectEnv(char value, String env, String display) { m_value = value; m_strEnv = env; m_strDisplay = display; }
		public char getValue() { return m_value; }
		public String getEnv() { return m_strEnv; }
		public String getDisplay() { return m_strDisplay; }
		public boolean isProd()
		{
			return (m_value == 'P' || m_value =='Q');
		}
		public static ConnectEnv getConnectEnv(String env)
		{
			if (env.equals(APP_Environment.DEV.toString()))
			{
				return DEV;
			}
			else if (env.equals(APP_Environment.TEST.toString()))
			{
				return TEST;
			}
			else if (env.equals(APP_Environment.UAT.toString()))
			{
				return UAT;
			}
			else if (env.equals(APP_Environment.PROD.toString()))
			{
				return PROD;
			}
			return AUTO;
		}
	};

	// 漲跌
	public enum ColorDef
	{
		@SerializedName("NONE")
		NONE(0),

		@SerializedName("UP")
		UP(R.color.sys_up),

		@SerializedName("UP_TRANS")
		UP_TRANS(R.color.sys_up_trans),

		@SerializedName("UP_LIMIT")
		UP_LIMIT(R.color.white),

		@SerializedName("EVEN")
		EVEN(R.color.white),

		@SerializedName("DOWN")
		DOWN(R.color.sys_down),

		@SerializedName("DOWN_TRANS")
		DOWN_TRANS(R.color.sys_down_trans),

		@SerializedName("DOWN_LIMIT")
		DOWN_LIMIT(R.color.white),

		@SerializedName("CLOSE")
		CLOSE(R.color.sys_grey),

		@SerializedName("VOLUME")
		VOLUME(R.color.sys_volume),

		@SerializedName("HALT")
		HALT(R.color.sys_halt),

		@SerializedName("HALT_BG")
		SYS_BG(R.color.sys_bg),

		@SerializedName("HALT_BG")
		HALT_BG(R.color.sys_grey),

		@SerializedName("BUY")
		BUY(R.color.sys_buy),

		@SerializedName("SELL")
		SELL(R.color.sys_sell),;

		private int m_nColorRes;

		ColorDef(int pColorRes)
		{
			m_nColorRes = pColorRes;
		}

		public int getColor()
		{
			int tColor = m_nColorRes;


			if (this == UP)
			{
				tColor = UP.m_nColorRes;
			}
			else if (this == DOWN)
			{
				tColor = DOWN.m_nColorRes;
			}
			else if (this == BUY)
			{
				tColor = BUY.m_nColorRes;
			}
			else if (this == SELL)
			{
				tColor = SELL.m_nColorRes;
			}
			else if(this == UP_TRANS)
			{
				tColor = UP_TRANS.m_nColorRes;
			}
			else if(this == DOWN_TRANS)
			{
				tColor = DOWN_TRANS.m_nColorRes;
			}

			try
			{
				tColor = BaseApp.getApp().getResources().getColor(tColor);
			}
			catch (Exception e)
			{

			}
			return tColor;
		}
	};



	public enum SubscribeQuoteType
	{
		ORDER(1,
				Fields.TOTALVOLUME,
				Fields.PRICE,
				Fields.OPENINTEREST,
				Fields.PRECLOSE,
				Fields.VOLUME,
				Fields.OPEN,
				Fields.DOWNLIMIT,
				Fields.UPLIMIT,
				Fields.W52_HIGH,
				Fields.W52_LOW,
				Fields.UPDOWN,
				Fields.UPDOWN_RATIO,
				Fields.AMOUNT,
				Fields.BUYDEALVOL,
				Fields.SELLDEALVOL,
				Fields.HIGH,
				Fields.LOW,
				Fields.AMPLITUDE),
		ORDER_BOOK_LV1(2,
				Fields.BID,
				Fields.ASK,
				Fields.BID_SIZE,
				Fields.ASK_SIZE),
		ORDER_BOOK_LV5(3,
				Fields.BIDP1,
				Fields.BIDP2,
				Fields.BIDP3,
				Fields.BIDP4,
				Fields.BIDP5,
				Fields.BIDV1,
				Fields.BIDV2,
				Fields.BIDV3,
				Fields.BIDV4,
				Fields.BIDV5,
				Fields.ASKP1,
				Fields.ASKP2,
				Fields.ASKP3,
				Fields.ASKP4,
				Fields.ASKP5,
				Fields.ASKV1,
				Fields.ASKV2,
				Fields.ASKV3,
				Fields.ASKV4,
				Fields.ASKV5),
		ORDER_BOOK_LV10(4,
				Fields.BIDP1,
				Fields.BIDP2,
				Fields.BIDP3,
				Fields.BIDP4,
				Fields.BIDP5,
				Fields.BIDV1,
				Fields.BIDV2,
				Fields.BIDV3,
				Fields.BIDV4,
				Fields.BIDV5,
				Fields.ASKP1,
				Fields.ASKP2,
				Fields.ASKP3,
				Fields.ASKP4,
				Fields.ASKP5,
				Fields.ASKV1,
				Fields.ASKV2,
				Fields.ASKV3,
				Fields.ASKV4,
				Fields.ASKV5,

				Fields.BIDP6,
				Fields.BIDP7,
				Fields.BIDP8,
				Fields.BIDP9,
				Fields.BIDP10,
				Fields.BIDV6,
				Fields.BIDV7,
				Fields.BIDV8,
				Fields.BIDV9,
				Fields.BIDV10,
				Fields.ASKP6,
				Fields.ASKP7,
				Fields.ASKP8,
				Fields.ASKP9,
				Fields.ASKP10,
				Fields.ASKV6,
				Fields.ASKV7,
				Fields.ASKV8,
				Fields.ASKV9,
				Fields.ASKV10);

		private int[] m_Value;
		private int m_Key;

		private SubscribeQuoteType(int pFieldsetKey, int... pFieldsetValue)
		{
			m_Key = pFieldsetKey;
			m_Value = pFieldsetValue;
		}

		public int getKey()
		{
			return m_Key;
		}

		public int[] getValue()
		{
			return m_Value;
		}
	}

}
